// get 请求打印参数
// http://localhost:3000/?user=jspang&age=18  例如仿问
const Koa=require('koa');
const app=new Koa();
const bodyparser=require('koa-bodyparser');//引用插件中间件

app.use(bodyparser());

app.use(async(ctx)=>{
  if(ctx.url==='/'&&ctx.method==='GET')
  {
      //显示表单页面
       let html=`
<h1>jspang koa2 requst post</h1>
<form method="post" action="/">
      <p>userName</p>
      <input name="userName"/><br/>
      <p>age</p>
      <input name="age"/><br/>
       <p>website</p>
       <input name="webSite"/><br/>
     <button type="submit">submit</button>
</form>
       <h1></h1>`;
       ctx.body=html;
  }else if(ctx.url=='/'&&ctx.method==='POST'){
      debugger
      let postData=ctx.request.body;
      ctx.body=postData;
  }else{
     ctx.body='<h1>404!</h1>';
  }
});

app.listen(3000,()=>{
    console.log('[demo] server is starting at port 3000')
})